package com.atguigu.boot;

import com.atguigu.boot.bean.Pet;
import com.atguigu.boot.bean.User;
import com.atguigu.boot.config.MyConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class MainApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(MainApplication.class, args);

        String[] names = run.getBeanDefinitionNames();
        for (String name : names){
            System.out.println(name);
        }
        //从容器中获取组件
     /*   Pet tom1 = run.getBean("tomcatPet", Pet.class);
        System.out.println(tom1.getName());
        Pet tom2 = run.getBean("tomcatPet", Pet.class);
        System.out.println("组件"+(tom1==tom2));

        MyConfig bean = run.getBean(MyConfig.class);
        System.out.println(bean);

        User user1 = bean.user01();
        System.out.println("user1="+user1.getName());
        User user2 = bean.user01();
        System.out.println("user2="+user1.getName());
        System.out.println(user1 == user2);*/

        boolean tomcatPet = run.containsBean("tomcatPet");
        System.out.println("打印容器中tomcatPet组件"+tomcatPet);

        boolean user = run.containsBean("user01");
        System.out.println("打印容器中user01组件"+user);

    }
}
